<template>
    <div>
        <h1>登录页面</h1>
        <br>
        名字：<input type="text" v-model="name">
        <br>
        密码：<input type="password" v-model="password">
        <br>
        <input type="button" @click="login" value="登录">
    </div>
</template>

<script>
export default {
    data:function(){
        return{
            name:'',
            password:'',
        }
    },
    methods:{
        login:function(){

            let formData = new FormData();
            formData.append('name', this.name);
            formData.append('password', this.password);

            this.axios({
                url: "http://127.0.0.1:8000/login/",
                method: "post",
                data: formData,
            }).then((res)=>{
                if(res.data.code==200)
                {
                    alert("登陆成功")
                    sessionStorage.setItem('uid',res.data.uid)
                    this.$router.push({path:'/show'})
                }
                else
                {
                    alert("登陆失败")
                }
            })

        },
    }
}
</script>
